Oh my zsh & iterm2

🔖 setting
Author

Guangyao Zhao

Published

Jun 14, 2022

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout…

iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.14 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.

1 安装 oh my zsh

1.1 安装方法 1

# 下载oh my zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

# 改变位置
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

如果报错:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused,有两种解决办法:

  1. 将 DNS 设置为:8.8.8.8或者114.114.114.114(参考文章:https://blog.csdn.net/bryong/article/details/108374261
  2. 使用安装方法 2

1.2 安装方法 2

# 下载oh my zsh
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

# 改变位置
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

# 清理缓存
brew cleanup

2 基本配置

2.1 修改主题

# 下载主题
/Users/daxiong/.oh-my-zsh/themes
git clone https://github.com/bhilburn/powerlevel9k.git

vim ~/.zshrc

# 修改
ZSH_THEME="agnoster"

修改主题

2.2 终端命令高亮和补全

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ## 下载高亮
git clone https://github.com/zsh-users/zsh-autosuggestions
vim ~/.zshrc  ## 下载补全

# 修改
plugins=(git
         zsh-autosuggestions
         zsh-syntax-highlighting)

命令高亮和补全

3 zsh 下的环境变量配置

Mac 的环境变量配置文件如下:

  1. /etc/profile
  2. /etc/paths
  3. ~/.bash_profile
  4. ~/.bash_login
  5. ~/.profile
  6. ~/.bashrc

前两个是系统级别的,系统启动就会加载。后面 3 个是当前用户级别的环境变量。后面几个按照从前往后的顺序读取,如果~/.bash_profile存在,则后面的几个文件就会被忽略不读了,如果不存在,才会依次读取后面的文件。~/.bashrc没有上述规则,它是 bash shell 打开的时候载入的。

也就是说在当前用户的目录下,如果有了.bash_profile文件就不会去加载.bashrc文件。所以如果要能正常加载,需要在.bash_profile文件的最末尾上加入如下语句:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

如果你没有修改过,上面的方法默认重启后就能生效。

但是,现在的 mac 上有些使用 zsh 这个作为默认的,所以在启动 shell 时默认不会按上面的套路去加载。如果想要正常加载.bashrc 文件时,就要找到用户目录下.zshrc 文件加入如下代码:

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

4 iterm2 远程控制

4.1 方法一

ssh -p22 root@slave1
ssh -p22 root@192.168.247.133

4.2 方法二

创建 shell 脚本文件:我的文件路径:/Users/kuma/hadoop_cluster/login.sh 注意:要赋予文件执行权限:chmod +x /Users/kuma/hadoop_cluster/login.sh

#!/usr/bin/expect
set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 3]\n"}
}
interact

4.3 配置 iterm2

Send text at start 的格式:脚本路径+端口号+服务器用户名+hostname+密码

例如:/Users/kuma/hadoop_cluster/login.sh 22 yowai slave1 00000000

Iterm2 设置